<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
    <%@page import="java.util.Date" %>
	<%@page import="java.text.SimpleDateFormat" %>
    <%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
    <%@taglib uri="/typeUtil"  prefix="typeUtil"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Welcome to yeser hotel</title>
</head>
<body>
	快速进入订单：<br>
	<form action='/hotel/reserve/getReserve'>
		订单id:<input name='id' type='text'><br>
		订单密码：<input name='password' type='text'><br>
		<input type="submit" value="提交"><br>
	</form>
	<c:if test="${empty requestScope.roomList }">
			<h1>暂时还没有可以住的房间</h1>
	</c:if>
	<c:if test="${!empty requestScope.roomList }">
		<table>
			<tr>
				<th>房间类型</th>
				<th>房间名称</th>
				<th>楼层</th>
				<th>价格</th>
				<th>图片</th>
				<th>添加时间</th>
				<th>备注</th>
				<th>处理</th>
				<th>设施</th>
			</tr>
			<c:forEach items="${requestScope.roomList }" var="room">
				<tr>
					<td>${typeUtil:getTypeName(room.typeId)}</td>
					<td>${room.name}</td>
					<td>${room.floor }</td>
					<td>${typeUtil:getTypePrice(room.typeId)*room.discount/100.0 }</td>
					<td><img id="img1" src="/hotel/upload/${room.pic }" width="200" height="200"/><br></td>
					<td>${room.addDate }</td>
					<td>${room.zcomment }</td>
					<td><button <c:if test="${room.condi==1}">disabled </c:if> onclick='checkBut(${room.id },${typeUtil:getTypePrice(room.typeId)*room.discount/100.0 })'>${room.condi==1?'已被预订':'预定' }</button></td>
					<td>${ typeUtil:getTypeFac(room.typeId)}</td>
				</tr>
			</c:forEach>
		</table>
		<button onclick='window.location.href="/hotel/visitor/roomList?page=${currentPage==1?1:currentPage-1}"'>上一页</button>&nbsp;&nbsp;
		<button onclick='window.location.href="/hotel/visitor/roomList?page=${currentPage+1}"'>下一页</button>
	</c:if>
	<%
	Date now=new Date();
	Date nextDay=new Date(now.getTime()+3600*24*1000);//一天后
	SimpleDateFormat format=new SimpleDateFormat("yyyy-MM-dd");//设置格式
	String nowStr=format.format(now);
	String nextStr=format.format(nextDay);
%>
	<div id="inputDiv">
		
		<input type="hidden" id="calcPrice">
		<input type="hidden" id="roomId" name='id'>
		入住时间:<input type="text" id="inTime" name='inDate' value='<%=nowStr %>' > <br>
		退房时间:<input type="text" id="outTime" name='outDate' value='<%=nextStr %>'><br>
		入住人数:<input type="text" id="num" name='num'><br>
		联系电话:<input type="text" id="phone" name='phone'><br>
		价格:<label id="cost"></label><br>
		备注:<br>
		<textarea cols="20" rows="20" id="zcomment" name='zcomment'></textarea><br>
		<button id="sub">提交</button><button id="cancel">取消</button>
	</div>
</body>
<style>
	#inputDiv{
		display:none;
	}

</style>
<script type="text/javascript" src="/hotel/js/jquery.min.js"></script>
<script type="text/javascript" src="/hotel/js/timeUtil.js"></script>
<script type="text/javascript">
	function checkBut(id,price){
		$('#roomId').val(id);
		//var add=document.getElementById('inputDiv')
		//add.style.display='block'
		$('#inputDiv').css("display","block");
		$('#calcPrice').val(price)
		calcRoomPrice()
	}
	function calcRoomPrice(){
		str1=$('#inTime').val();
		str2=$('#outTime').val();
		$('#cost').text(getDurDays(str1,str2)*$('#calcPrice').val())
	}
	$('#cancel').click(function(){
		$('#inputDiv').css("display","none");
	})
	$.ajaxSettings.async = false;
	$('#sub').click(function(){
		data={'id':$('#roomId').val(),'inDate':$('#inTime').val(),'outDate':$('#outTime').val(),'num':$('#num').val(),
				'phone':$('#phone').val(),'zcomment':$('#zcomment').val()}
		//alert(JSON.stringify(data))
		//alert('房间id:'+$('#roomId').val()+'\n入住时间:'+$('#inTime').val()+'\n退房时间'+$('#outTime').val()+'\n入住人数'+$('#num').val()
		//		+'\n联系电话'+$('#phone').val()+'\n备注'+$('#zcomment').text()+"\n价格:"+$('#cost').text())
		$.post('/hotel/reserve/checkRoom',data,function(str){
			//alert(str)
			//while(str=='');
			var res=eval('(' +str + ')')
			//alert(res.object)
			if(res.code!=0){
				alert(res.message)
				
				obje=res.object
				//alert(obje)
				if(res.code==1)
					window.location.href="/hotel/reserve/getReserve?id="+obje.orderId
				return;
			}else{
				obje=res.object
				//alert(obje)
				window.location.href="/hotel/reserve/getReserve?id="+obje.orderId
			}
		})
	})
	$.ajaxSettings.async = true
	$('#outTime').blur(function(){
		//alert('test')
		calcRoomPrice()
	})
	
</script>
</html>